const crypto = require("crypto");
const fs = require("fs");

const getShaValue = (data) => {
  const shaHash = crypto.createHash("sha256");
  shaHash.update(data);
  return shaHash.digest("hex");
};

const getFileShaValue = (filePath,callback) => {
  const hash = crypto.createHash("md5");
  const fileStream = fs.createReadStream(filePath);
  fileStream.pipe(hash);
  fileStream.on("end", () => {
    const hashValue = hash.digest("hex");
    console.log(`MD5 hash of file: ${hashValue}`);
    callback(hashValue)
  });
};

const getMd5Value = (data) => {
  const md5Hash = crypto.createHash("md5");
  md5Hash.update(data);
  return md5Hash.digest("hex");
};

const shaValue = getShaValue("hello nodejs!");
console.log("shaValue: ", shaValue);
const md5Value = getMd5Value("hello nodejs!");
console.log("md5Value: ", md5Value);
getFileShaValue("./README-HASH.md");
